package org.cskj.demo.service.imp;

import org.cskj.demo.mapper.ShopMapper;
import org.cskj.demo.pojo.Shop;
import org.cskj.demo.pojo.ShopExample;
import org.cskj.demo.pojo.ShoptypeExample;
import org.cskj.demo.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ShopImp implements ShopService {
    @Autowired
    private ShopMapper shopMapper;
    @Override
    public List<Shop> seletcLimit(int page, int pagesize) {
        Map map=new HashMap();
        map.put("start",(page-1)*pagesize);
        map.put("end",pagesize);
        System.out.println(map);
        List<Shop> shops = shopMapper.selectq(map);
        return shops;
    }
    public int count(){
        int i = shopMapper.countByExample(null);
        return i;
    }
    public List<Shop> getall(){
        List<Shop> list = shopMapper.selectByExample(null);
        return list;
    }
    public Shop selectByKey(Integer id){
        Shop shop = shopMapper.selectByPrimaryKey(id);
        return shop;
    }
    public int update(Shop shop){
        int i = shopMapper.updateByPrimaryKeySelective(shop);
        return i;
    }
    public int insert(Shop shop){
        int i = shopMapper.insertSelective(shop);
        return i;
    }
    public List<Shop> check(String name){
        ShopExample example = new ShopExample();
        ShopExample.Criteria criteria = example.createCriteria();
        criteria.andShopnameEqualTo(name);
        List<Shop> list = shopMapper.selectByExample(example);
        return list;
    }
    public boolean checkname(String shopname){
        ShopExample example = new ShopExample();
        ShopExample.Criteria criteria = example.createCriteria();
        criteria.andShopnameEqualTo(shopname);
        List<Shop> list = shopMapper.selectByExample(example);
        if (list.size()>0){
            return false;
        }else {
            return true;
        }
    }
    public int delete(int shopid){
        int i =shopMapper.deleteByPrimaryKey(shopid);
        return i;
    }

}
